import React        from 'react';
import Header       from 'component/header/index.jsx';
import AddrList     from '../address/addresslist.jsx'
import { Link }     from 'react-router-dom';
import appData from '../../util/data.json';
import './address.scss'
class Address extends React.Component{
    constructor(){
        super();
        this.state = {
            addrObj: appData.addrObj
        }
    }
    goBack(){
        this.props.history.push('/');  
    }
    delectAddr(e){
       this.setState({addrObj: this.state.addrObj.splice(e-1,1)})
    }
    changeDefault(val){
        alert('change default'+val)
    }
render(){
    return(
        <div id="address">
            <Header title='我的地址' goBack={e=>{this.goBack(e)}}/>
            <div className="content myaddr ">
            <AddrList delectAddr={e=>{this.delectAddr(e)}} data={this.state.addrObj} changeDefault={e=>{this.changeDefault(e)}}/>
            </div>
            <Link to={'/addrAdd'} className="weui-btn xl" id="newaddr">添加新地址</Link>
        </div>
    )
}
}
export default Address;